﻿<%@ Page Title="ForestSickness" Language="C#" MasterPageFile="~/EasyUI.master" AutoEventWireup="true" CodeBehind="List.aspx.cs" Inherits="cebao.Web.ForestSickness.List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../CSS/IconExtension.css" rel="stylesheet" />
    <script src="../Script/export.js"></script>
    <script src="../Script/username.js"></script>
    <script src="../Script/datetime.js"></script>    
    <script type="text/javascript">
        //预警用
        var pid = 0;
        var atype = "";
        var mleveltype = [{ "id": "4", "text": "国家级", "iconCls": "icon-gj", "checked": true }, { "id": "3", "text": "省级", "iconCls": "icon-sj", "checked": true }, { "id": "2", "text": "市级", "iconCls": "icon-ssj", "checked": true }, { "id": "1", "text": "县级", "iconCls": "icon-xj", "checked": true }];

        $(function () {
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    var level = data[0].level;
                    if (level == 0) {
                        $("#listuser").hide();
                    }

                }
            });
            $("#mlevel").combotree({ data: mleveltype, width: 120, valueField: 'id', textField: 'text', editable: false, panelHeight: 'auto', multiple: true, checkbox: true });
            year = new Date().getFullYear();
            $('#jd').combobox({
                onSelect: function (newValue, oldValue) {
                    if (newValue.text == '一季度') {
                        $("#StartTime").datebox("setValue", year + "-1-1");
                        $("#EndTime").datebox("setValue", year + "-3-31");
                    }
                    else if (newValue.text == '二季度') {
                        $("#StartTime").datebox("setValue", year + "-4-1");
                        $("#EndTime").datebox("setValue", year + "-6-30");
                    }
                    else if (newValue.text == '三季度') {
                        $("#StartTime").datebox("setValue", year + "-7-1");
                        $("#EndTime").datebox("setValue", year + "-9-30");
                    }
                    else if (newValue.text == '四季度') {
                        $("#StartTime").datebox("setValue", year + "-10-1");
                        $("#EndTime").datebox("setValue", year + "-12-31");
                    }
                    else if (newValue.text == '当天') {
                        var curr_time = new Date();
                        var tc_time = new Date(curr_time.getTime() + 24 * 60 * 60 * 1000);
                        var strDate = curr_time.getFullYear() + "-";
                        strDate += curr_time.getMonth() + 1 + "-";
                        strDate += curr_time.getDate();
                        var strDateend = tc_time.getFullYear() + "-";
                        strDateend += tc_time.getMonth() + 1 + "-";
                        strDateend += tc_time.getDate();
                        $("#StartTime").datebox("setValue", strDate);
                        $("#EndTime").datebox("setValue", strDateend);
                    }
                }
            });
            InitGird();
            InitTree();
        });
        function InitTree() {
            $('#pt').tree({
                url: '../harmfulinfo/GetHarm.ashx?type=1', //请求数据的页面               
                width: '100%', //宽度                
                lines: true,
                method: 'post',
                checkbox: true,
                queryParams: { "action": "queryta" },
                onCheck: function (node) {
                    reloadgrid();
                },
                onLoadSuccess: function (node, param) {
                    $('#pt').tree("collapseAll");
                    var node = $('#pt').tree("getRoot");
                    if (node)
                        $('#pt').tree("expand", node.target);
                }
            });
            $('#pt1').tree({
                url: '../harmfulinfo/GetHarm.ashx?type=1', //请求数据的页面               
                width: '100%', //宽度                
                lines: true,
                method: 'post',
                checkbox: true,
                queryParams: { "action": "queryth" },
                onCheck: function (node) {
                    reloadgrid();
                },
                onLoadSuccess: function (node, param) {
                    $('#pt1').tree("collapseAll");
                    var node = $('#pt1').tree("getRoot");
                    if (node)
                        $('#pt1').tree("expand", node.target);
                }
            });
        }
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                title: '虫情动态_病害', //表格标题
                url: 'GetSickness.ashx', //请求数据的页面
                sortName: 'inputTime', //排序字段
                idField: 'fs_id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[//							                    
	                { title: '区域', field: 'address', width: 150, sortable: true },
                    { title: '树种', field: 'pname', width: 80 },
                    {
                        title: '病名', field: 'hname', width: 120, formatter: function (value, row, index) {
                            return '<a href="#" onclick="sendalarm(\'' + row.fs_id + '\',\'sickness\')">' + row.hname + '</a>';
                        }
                    },
                    { title: '统计单位', field: 'totalUnit', width: 120 },
                    { title: '统计数据', field: 'totalCount', width: 80 },
                    {
                        title: '发生程度', field: 'happenpro', width: 100
                    },
                    {
                        title: '监测人', field: 'uname', width: 80, formatter: function (value, row, index) {
                            return '<a href="#" onclick="top.addTab(\'病害' + row.uname + '\',\'/ForestSickness/listr.aspx?uid=' + row.uid + '&qh=' + row.remark + '\', \'icon icon-magic\');">' + row.uname + '</a>';

                        }
                    },
                    { title: '监测点', field: 'mname', width: 150 },
                    {
                        title: '监测时间', field: 'inputTime', width: 150, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    }
                ]
                ],
                rowStyler: function (index, row) {
                    var value = row.happenpro;
                    if (value == '轻度以下') {
                        return 'color:green; font-weight:bold;';
                    }
                    else if (value == '轻度') {
                        return 'color:blue; font-weight:bold;';
                    }
                    else if (value == '中度') {
                        return 'color:#FF00FF; font-weight:bold;';
                    }
                    else if (value == '重度') {
                        return 'color:red; font-weight:bold;';
                    }
                },
                toolbar: "#tab_toolbar",
                queryParams: { "action": "queryhc" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号
            });

        }
        function sendalarm(spid, satype) {
            $('#adlg').dialog({
                onOpen: function () {

                    pid = spid;
                    atype = satype;
                }
            });
            $('#adlg').dialog('open').dialog('refresh', '../alarminfo/add.aspx?pid=' + spid + '&atype=' + satype);
        }
        function getids(nodes) {
            var ids = "";
            for (var i = 0; i < nodes.length; i++)
                ids = ids + nodes[i].id + ",";
            if (ids != "")
                ids = ids.substr(0, ids.length - 1);
            return ids;

        }

        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");
            var anodes = $('#pt').tree('getChecked');
            var hnodes = $('#pt1').tree('getChecked');           
            if (anodes.length != 0) {
                var idstr = getids(anodes);
                queryParams.idstr = idstr;
            }
            else {
                queryParams.idstr = "";
            }
            if (hnodes.length != 0) {
                var idh = getids(hnodes);
                queryParams.idh = idh;
            }
            else {
                queryParams.idh = "";
            }
            var otype = $("#otype").val();
            var mlevel = $("#mlevel").combotree("getValues").toString();
            queryParams.mlevel = mlevel;
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;            
            queryParams.otype = otype;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#tt').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');

        }
        
      

    </script>
    <style type="text/css">
        .fitem {
            width: 100%;
            
        }

            .fitem label {
                width:60px;
                line-height: 22px;
            }

            .fitem input {
                width: 120px;
            }
             .dl1 {
            color:green;
            font-weight:bold;
        }
        .dl2 {
            color:blue;
            font-weight:bold;
        }
        .dl3 {
            color:yellow;
            font-weight:bold;
        }
        .dl4 {
            color:red;
            font-weight:bold;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="easyui-layout" style="width: 100%; height: 100%;" id="mycon">
       <div region="west" split="true"  style="width: 350px; " id="west">
            <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'west'" style="width: 150px;overflow-y: auto">
                    <ul id="pt"></ul>
                </div>
                <div data-options="region:'center'" style="overflow-y: auto">
                    <ul id="pt1"></ul>
                </div>
            </div>
        </div>
        <div region="center" style="background: #eee; overflow-y: hidden">
            <table id="tt">
            </table>
        </div>
        <div id="tab_toolbar" style="padding: 4px;">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>
                    <td style="padding-left: 2px">
                        <div>
                            时间从:  
           <input id="StartTime" class="easyui-datebox" style="width: 100px" />
                            到:  
           <input id="EndTime" class="easyui-datebox" style="width: 100px" />
                             <select id="jd" class="easyui-combobox" name="jd" style="width:80px;">
                    <option value="季度">季度</option>
                                <option value="一季度">一季度</option>
                                <option value="二季度">二季度</option>
                                <option value="三季度">三季度</option>
                                <option value="四季度">四季度</option>
                    <option value="当天">当天</option>
</select>      
                            <input id="mlevel"  name="mlevel" />  
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Export('excel', $('#tt'));">导出</a>
                            
                            <a id="listuser" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-people'" onclick="top.addTab('按用户浏览病害','/ForestSickness/listuser.aspx', 'icon icon-magic');">按用户进行浏览</a>
                        <input name="idstr" id="idstr" type="hidden" />
                    <input name="idh" id="idh" type="hidden" />
                    <input name="city" id="city" type="hidden" />
                    <input name="st" id="st" type="hidden" />
                    <input name="et" id="et" type="hidden" />
                    <input name="otype" id="otype" type="hidden" />
                        </div>
                    </td>
                </tr>
            </table>

        </div>       
    </div>
     <div id="adlg" class="easyui-dialog" title="预警发送" style="width:400px;height:300px;"   
        data-options="closed:true,shadow:false,resizable:true,modal:true"></div>
</asp:Content>